#include "Logger.h"

#include <SFML/Graphics.hpp>
#include "../../views/helpers/graphic/ColoursPalette.h"

using namespace Utils::GUI;

Logger::Logger()
	: Control(), max_messages(8)
{
	Shape = sf::Shape::Rectangle(0, 0, 600, 150, sf::Color(Views::Helpers::Graphic::Colours::Dark));
}

void Logger::addMessage(std::string text)
{
	Label* Message = new Label(text);
	Message->Move(10, 0);
	addChild(Message);
	messages.insert(messages.begin(), Message);
	Control::Draw(true);
}

void Logger::Draw(bool display, sf::RenderWindow* window)
{
	while(messages.size() > max_messages)
	{
		delete messages[messages.size() - 1];
		messages.pop_back();
	}
	int alpha = 255;
	int pos = 5;
	for (MessagesList::iterator i = messages.begin(); i != messages.end(); ++i)
	{
		(*i)->Move(0, GetRect().Top - (*i)->GetRect().Top);
		(*i)->Move(0, pos);
		(*i)->SetFontColour(sf::Color(255, 255, 255, alpha));
		pos += 18;
		alpha -= 30;
	}
	Control::Draw(display, window);
}

